 <%--
  *  File:    CustomerCollateEdit.jsp
  *  @Author: Rogerwang
  *  Date:    2006/4/25
  *
  *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
  *  All rights reserved.
  *
  *  This software is the confidential and proprietary information of Oval
  *  Technologies, Inc. ("Confidential Information").  You shall not
  *  disclose such Confidential Information and shall use it only in
  *  accordance with the terms of the license agreement you entered into
  *  with Oval.
 --%> 
<%@ page import="java.text.*" %>
<%@ page contentType = "text/html;charset=UTF-8" %>

 <%
   //init param
   Category cat = Category.getInstance("jsp.CustomerCollateEdit");
   String strTableName = "v_customercollateedit";
   String strModuleName = "CM";
   String privilegeCode = "E0162";
     String contextPath = request.getContextPath();
 %>
        <%@ include file="/inc/CommonHeader.inc" %>
        <%@ include file="/inc/OvalLocationDefault.inc" %>
		<%@ include file="/inc/Print.inc"%>
		<%@ include file="/rpt/ReportURL.inc" %>
		
 <%
   //get curuser info
   HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
   String strCurOrgName = (String)CurUserInfo.get("orgname");
   Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
   String  isadmin=(String)CurUserInfo.get("isadmin");
   if(nCurOrgId == null)
   {
     nCurOrgId = new Integer(-1234567);
   }
   System.out.println(isadmin);
 %>




 <html>
 <head>

 <title>CustomerCollateEdit</title>
 <PageFlow:CheckPageFlow pageName="p_customercollateedit"/>
 	 <%


java.util.Calendar cal = java.util.Calendar.getInstance();      
int day = cal.get(Calendar.DAY_OF_MONTH);

String dateFormat = (String)session.getAttribute("dateformat");
if(dateFormat==null)dateFormat = "yyyy-MM-dd";
%>

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <%@ include file="/inc/CatchError.inc" %>
 <script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/SummaryDivision.js"></script>
 <link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
 <script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/opal2/mootools.js"></script>
<%@ include file="/inc/NewCalendar.inc" %>
 <%@ include file="/inc/SummaryDivision.inc" %>
 <%
   Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
   if(totalsummary == null)
   {
     totalsummary = new Vector();
   }
   
	String orgoptionvalue = (String)pageContext.getAttribute("orgoption");
	if(orgoptionvalue == null)orgoptionvalue = "1";
	
		String optionvalue = (String)pageContext.getAttribute("optionvalue");
	
 %>
 <script>
 var popwindow;
 function page_summary(actionvalue,orderbyname)
 {
     if(isEmpty(cform.keyname.value) && false)
     {
         alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomerKey"))%>");
         return;
     }
     //if(!checkDate()) return;

   var editform = summaryPrepare(cform,actionvalue,orderbyname);
   editform.action = "CustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=y";
   editform.target = "_self";
   isRunning = true;
   editform.submit();
 }


 function checkAll()
 {
      if(cform.selorgids)
      {
         if(cform.selorgids.length)
         {
             for(var i=0;i<cform.selorgids.length;i++)
             {

                  cform.selorgids[i].checked=cform.selectall.checked;
             }
         }else
         {
             cform.selorgids.checked=cform.selectall.checked;
         }


      }
 }
 function page_update()
 {
  
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_UPDATE") %>");
    if(!flag)
  return;
  document.cform.action = "CustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=u";
   document.cform.target = "_self";
   isRunning = true;
   document.cform.submit();
   alert("已修改完成！");
 }
 
 function page_go()
 {
     if(isNullChecked(cform.selorgids)==true)
   {
       alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
       return;
   }
    if(isEmpty(cform.orgid.value))
     {
         alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomerCollateCode"))%>");
         return;
    }
   var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE") %>");
   if(!flag)
     return;

 <%--emptyToNull(document.cform);--%>
 document.cform.action = "CustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=s";
   document.cform.target = "_self";
   document.cform.pageaction.value = "OrderBy";
   isRunning = true;
   document.cform.submit();
 }

 var type;

 function page_selectProvince(obj)
 {
   type=obj;
   if(popwindow!=null)
    popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
 }

 function page_setRegion(code,name,id)
 {
	 var regioncode;
     var regionname;
     var regionid;
     var citycode;
     var cityname;
	 var countycode;
	 var countyname;
     if(type=='customer'){
		 regioncode=eval('document.cform.regioncode');
         regionname=eval('document.cform.regionname');
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }else if(type=='newcustomer'){
		 regioncode=eval('document.cform.newregioncode');
         regionname=eval('document.cform.newregionname');
         citycode=eval('document.cform.newcitycode');
         cityname=eval('document.cform.newcityname');
		 countycode = eval('document.cform.newcountycode');
		 countyname = eval('document.cform.newcountyname');
     } else{
		 regioncode=eval('document.cform.sregioncode');
         regionname=eval('document.cform.sregionname');
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }

     if(code != regioncode.value && type=='newcustomer'){
         citycode.value='';
         cityname.value='';
		 countycode.value='';
         countyname.value='';
     }else{
		 citycode.value='';
         cityname.value='';
	 }
   regioncode.value = code;
   regionname.value = name;
   //regionid.value = id;
   if(type!='newcustomer'){
	cform.newsregioncode.value = code;
	cform.newsregionname.value = name;
   }
   if (popwindow != null)
     popwindow.close();
 }

 function page_selectCity(obj,flag,grade)
 {
	 var proidstring = document.cform.proid.value;
     var sregioncode = document.cform.sregioncode.value;
	 var sregionname = document.cform.sregionname.value;
     type=obj;
      var regioncode;
     if(type=='customer')
     {
         regioncode=eval('document.cform.regioncode');
     }
     else
     {
         regioncode=eval('document.cform.sregioncode');
     }
   if(isEmpty(regioncode.value))
   {
     alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
     return;
   }
   if(popwindow!=null)
     popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN' + '&regioncode=' + regioncode.value +'&proidstring='+proidstring + '&flag=' + flag+'&grade='+grade,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
 }

 function page_setCity(code,name,id,flag)
 {
     if(type=='newcustomer'){
		page_setCity1(code,name,id,flag);
		return;
	 }
	 var citycode;
     var cityname;
     if(type=='customer'){
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }else{
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }
   citycode.value = code;
   cityname.value = name;
   if(type!='newcustomer'){
	cform.newscitycode.value = code;
	cform.newscityname.value = name;
   }
   if (popwindow != null)
     popwindow.close();
 }
 function page_setCity1(code,name,id,flag)
{
	if(flag == "county"){
		document.cform.newcountycode.value = code;
		document.cform.newcountyname.value = name;
	}else {
		document.cform.newcitycode.value = code;
		document.cform.newcityname.value = name;
		document.cform.newcountycode.value = " ";
    	document.cform.newcountyname.value = " ";
	}
  if (popwindow != null)
    popwindow.close();
}

function page_selectCity1(obj,flag,grade)
{
  type=obj;
  var regioncode = document.cform.newregioncode.value;
  var parentcitycode = document.cform.newcitycode.value;
  if(flag=="city")parentcitycode='null';
  if(regioncode=="" || regioncode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
    return;
    if(parentcitycode=="" || parentcitycode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_City"))%>");
    return;
  }
  }
  
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN&regioncode=' + regioncode + '&flag=' + flag+'&grade='+grade+'&parentcitycode='+parentcitycode,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

 function page_changeRegion(obj)
 {
	var regioncode = cform.newsregioncode.value;
	page_cleanregionandcity();
	if(regioncode == "")return;
    var datahandler = new  DataHandler() ;
    datahandler.add_params("regioncode" , regioncode, 'String') ;
    datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
    datahandler.getResult("regioncode" ,"document.cform.sregioncode");
    datahandler.getResult("regioncode" ,"document.cform.newsregioncode");
    datahandler.getResult("regionname" ,"document.cform.newsregionname");
    datahandler.getResult("regionname" ,"document.cform.sregionname");
    datahandler.add_job("j_getregionbycode");
    datahandler.runDataHandler();
 }

function page_checkRegion(){
	if(cform.sregioncode.value == ""){
		cform.newsregioncode.value = "";
	}
}
 
 function page_changeCity(obj)
 {
	var regioncode = cform.newsregioncode.value;
	var citycode = cform.newscitycode.value;
	if(isEmpty(regioncode))
	{
	  alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
	  return;
	}
	page_cleancity();
	if(regioncode == "")return;
	var datahandler = new  DataHandler() ;
	datahandler.add_params("regioncode" , regioncode, 'String') ;
	datahandler.add_params("citycode" , citycode, 'String') ;
	datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
	datahandler.getResult("citycode" ,"document.cform.scitycode");
	datahandler.getResult("citycode" ,"document.cform.newscitycode");
	datahandler.getResult("cityname" ,"document.cform.newscityname");
	datahandler.getResult("cityname" ,"document.cform.scityname");
	datahandler.add_job("j_getcitybycode");
	datahandler.runDataHandler();
 }
 
function page_cleanregionandcity(){
	cform.sregioncode.value = "";
	cform.newsregioncode.value = "";
	cform.sregionname.value = "";
	cform.newsregionname.value = "";
	cform.scitycode.value = "";
	cform.newscitycode.value = "";
	cform.scityname.value = "";
	cform.newscityname.value = "";
}

function page_cleancity(){
	cform.scitycode.value = "";
	cform.newscitycode.value = "";
	cform.scityname.value = "";
	cform.newscityname.value = "";
}
 function page_selectCustomer()
 {
    window.open("<%=contextPath%>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>", "newwindow", "height=450, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")
 }
 function page_setOrg(orgid,orgname,orgcode)
 {
    document.cform.orgid.value=orgid;
    document.cform.orgname.value=orgname;
    document.cform.orgcode.value=orgcode;
	hiddenFrm();
 }

 function page_reload()
{
   document.cform.orgid.value="";
   document.cform.orgname.value="";
   if(isEmpty(document.cform.orgcode.value))
   {
        document.cform.orgcode.value = "";
        return;
   }
    var  datahandler = new  DataHandler() ;
    datahandler.add_params("selectoption" , "xjpcustomer") ;
    datahandler.add_params("searchname" , "orgcode") ;
    datahandler.add_params("searchvalue" , document.cform.orgcode.value) ;
    datahandler.getResultFromHashMap("orgsummary" ,"orgcode" ,"document.cform.orgcode");
    datahandler.getResultFromHashMap("orgsummary" ,"orgid" ,"document.cform.orgid");
    datahandler.getResultFromHashMap("orgsummary" ,"orgname" ,"document.cform.orgname");
    datahandler.add_job("getrelatedorg") ;
	datahandler.add_function("page_checkOrg()");
    datahandler.runDataHandler ();
}

function page_checkOrg(){
	if(cform.orgid.value == ""){
		cform.orgcode.value = "";
	}
}
 
 function setNewRegionCode(newareacode,areaname,regioncode){
        var length = newareacode.length;
	    var regioncodearray= regioncode;
	    var areanamearray=areaname;
		var areaidString = "";
		var areanameString = "";
		var regioncodeString = "";
		var StrsRegioncode = "";
	   	var StrsRegionname = "";
	  for(var i = 0;i < length;i++){
			if(i == length - 1){
				areaidString = areaidString + newareacode[i].value;
				areanameString = areanameString + "'" + areanamearray[i].value + "'";
				regioncodeString = regioncodeString + "'" + regioncodearray[i].value + "'";
				
				StrsRegionname = StrsRegionname + areanamearray[i].value;
			    StrsRegioncode = StrsRegioncode + regioncodearray[i].value;
			}else{
				areaidString = areaidString + newareacode[i].value + ",";				
				areanameString = areanameString + "'" + areanamearray[i].value + "'" + ",";
				regioncodeString = regioncodeString + "'" +regioncodearray[i].value + "'" + ",";
				
				StrsRegionname = StrsRegionname + areanamearray[i].value + ",";
				StrsRegioncode = StrsRegioncode +regioncodearray[i].value + ",";
			}			
		} 
		cform.sregionname.value = "";
		cform.sregionname.value = areanameString;
		cform.scityname.value = "";
		cform.proid.value = "";
		cform.proid.value = areaidString;
		cform.sregioncode.value = "";
		cform.sregioncode.value = regioncodeString;
		
		cform.newsregionname.value = "";
	    cform.newsregionname.value = StrsRegionname;
		cform.newsregioncode.value = "";
		cform.newsregioncode.value = StrsRegioncode;
 }
		
 function setNewCityCode(newareacode,areaname,citycodeinfo){
	  var length = newareacode.length;
	  var citycodearray=citycodeinfo;
	  var areanamearray=areaname;
		var areaidString = "";
		var areanameString = "";
		var citycodeString = "";
		var StrsCitycode = "";
	   	var StrsCityname = "";
		for(var i = 0;i < length;i++){
			if(i == length - 1){
				areaidString = areaidString + newareacode[i].value;
				areanameString = areanameString + "'" + areanamearray[i].value + "'";
				citycodeString = citycodeString + "'" + citycodearray[i].value + "'";
				
				StrsCityname = StrsCityname + areanamearray[i].value;
				StrsCitycode = StrsCitycode + citycodearray[i].value;
			}else{
				areaidString = areaidString + newareacode[i].value + ",";
				areanameString = areanameString + "'" + areanamearray[i].value + "'" + ",";
				citycodeString = citycodeString + "'" + citycodearray[i].value + "'" + ",";
				
				StrsCityname = StrsCityname + areanamearray[i].value + ",";
			    StrsCitycode = StrsCitycode + citycodearray[i].value + ","; 
			}			
		}
		cform.scityname.value = "";
		cform.scityname.value = areanameString;
		cform.cityid.value = "";
		cform.cityid.value = areaidString;
		cform.scitycode.value = "";
		cform.scitycode.value = citycodeString;
		
		cform.newscityname.value = "";
		cform.newscityname.value = StrsCityname;
		cform.newscitycode.value = "";
		cform.newscitycode.value = StrsCitycode;
 }

function page_upload(){
		this.location.href = "<%= contextPath%>/phap/masterdata/spm/UploadEXL.jsp?first=ZZ&second=ZB01&third=Z0608&sheetname=customercollate&<%= OvalTools.randomURL() %>";
}

//function page_download(){
//		this.location.href = "<%= contextPath%>/phap/masterdata/spm/export/ExportCustomerCollate.jsp?scruletype=1&<%= OvalTools.randomURL() %>";
//}

function page_download(){
    startdate=document.cform.startdate.value;
    enddate=document.cform.enddate.value;
	keyname = document.cform.keyname.value;	
	keynameexc =document.cform.keynameexc.value;
	sregioncode =document.cform.sregioncode.value;
	scitycode = document.cform.scitycode.value;
	userid =document.cform.userid.value;
	regionid= document.cform.regionid.value;
	areaids=document.cform.areaids.value;
	searchname = document.cform.searchname.value;
	searchvalue = document.cform.searchvalue.value;
	if(searchvalue=='' || searchvalue==null)searchvalue='-1';
	var temp = document.getElementsByName("clstflag");
	var clstflag = "";
    for(var i=0;i<temp.length;i++){
     if(temp[i].checked)var clstflag = temp[i].value;
    }
	if(searchname=="dealername")
	searchname="c.orgname"
	else if(searchname=="dealercode")
	searchname="c.orgcode"
	else if(searchname=="custcolcode")
	searchname="b.orgname"
	else if(searchname=="statusname")
	searchname="e.valuename"
	 <%if("Y".equals(isadmin)){%>
 	 window.open("<%= reportURL %>/servlet/ExcecuteReport/CustomerCollateData.sox?__format=xlsx&__folder=/ovalreport&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate );	
     <%}else{%>
     window.open("<%= reportURL %>/servlet/ExcecuteReport/CustomerCollateData.sox?__format=xlsx&__folder=/ovalreport&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&employeeid="+userid+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate);	
      <%}%>
 }

function big_download(){
    startdate=document.cform.startdate.value;
    enddate=document.cform.enddate.value;
	keyname = document.cform.keyname.value;	
	keynameexc =document.cform.keynameexc.value;
	sregioncode =document.cform.sregioncode.value;
	scitycode = document.cform.scitycode.value;
	userid =document.cform.userid.value;
	regionid= document.cform.regionid.value;
	areaids=document.cform.areaids.value;
	searchname = document.cform.searchname.value;
	searchvalue = document.cform.searchvalue.value;
	if(searchvalue=='' || searchvalue==null)searchvalue='-1';
	var temp = document.getElementsByName("clstflag");
	var clstflag = "";
    for(var i=0;i<temp.length;i++){
     if(temp[i].checked)var clstflag = temp[i].value;
    }
	if(searchname=="dealername")
	searchname="c.orgname"
	else if(searchname=="dealercode")
	searchname="c.orgcode"
	else if(searchname=="custcolcode")
	searchname="b.orgname"
	else if(searchname=="statusname")
	searchname="e.valuename"
	
	var url ="<%=newreportURL %>/xlsrpt?reportname=CustomerCollateData";
	<%if("Y".equals(isadmin)){%>
 	 //window.open("<%= reportURL %>/servlet/ExcecuteReport/CustomerCollateData.sox?__format=xlsx&__folder=/ovalreport&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate;
 	 url=url+"&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate+"&timestamp="+Date.parse(new Date());
    <%}else{%>
     //window.open("<%= reportURL %>/servlet/ExcecuteReport/CustomerCollateData.sox?__format=xlsx&__folder=/ovalreport&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&employeeid="+userid+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate;	
     url=url+"&rownum=2&keyname="+escape(encodeURI(keyname))+"&areaids="+areaids+"&employeeid="+userid+"&clstflag="+clstflag+"&scitycode="+scitycode+"&sregioncode="+sregioncode+"&keynameexc="+escape(encodeURI(keynameexc))+"&searchname="+searchname+"&searchvalue="+escape(encodeURI(searchvalue))+"&startdate="+startdate+"&enddate="+enddate+"&timestamp="+Date.parse(new Date());
    <%}%>
    DataReport(url);
    /*
	  var objform = document.createElement("form");
	  document.body.appendChild(objform);
	  
	  var indexQM = url.indexOf("?");
	  var actionurl = url.substring(0, indexQM);  
	  var query = url.substring(indexQM + 1); 
	  if(indexQM>=0){
		var params= url.substring(indexQM+1).split("&");
		for(var i=0; i<params.length; i++){
		  var keyValuePair =params[i].split("=");
		  var input = document.createElement("input");
	      input.type="hidden";
	      input.name  = keyValuePair[0];
	      input.value = keyValuePair[1];
	      objform.appendChild(input);
	    }
	  }
	  objform.action = url;
	  objform.target = "_blank";
	  objform.method = "POST";
	  objform.submit();
	  //删除该 form  
	  document.body.removeChild(objform); */
 }
 
 function page_excelload(){
		userid =document.cform.userid.value;
		areaids=document.cform.areaids.value;
	    startdate=document.cform.startdate.value;
	    enddate=document.cform.enddate.value;
	    <%if("Y".equals(isadmin)){%>
	 	 window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/TerminalMasterDataDownLoad.sox?__format=xlsx&__folder=/ovalreport&rownum=2&areaids="+areaids+"&startdate="+startdate+"&enddate="+enddate;	
	    <%}else{%>
	     window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/TerminalMasterDataDownLoad.sox?__format=xlsx&__folder=/ovalreport&rownum=2&employeeid="+userid+"&areaids="+areaids+"&startdate="+startdate+"&enddate="+enddate;	
	    <%}%>
 }

var popwindow;

function page_initDiv(){
	document.cform.neworgcode.value="";
    document.cform.neworgname.value="";
    
    document.cform.newregioncode.value="";
    document.cform.newregionname.value="";
    document.cform.newcitycode.value="";
    document.cform.newcityname.value="";
    document.cform.newcountycode.value="";
    document.cform.newcountyname.value="";
    document.cform.globalpccode.value="-1";
}

function subDiv(n) {
    neworgcode = document.cform.neworgcode.value;
    neworgname = document.cform.neworgname.value;
    regioncode = document.cform.newregioncode.value;
    citycode = document.cform.newcitycode.value;
    countycode = document.cform.newcountycode.value;
    globalpccode = document.cform.globalpccode.value;
    if(n!=1){
		if(!checkForm(document.cform))return;
	}
    var  datahandler = new  DataHandler();
	datahandler.add_params("neworgcode" , neworgcode, 'String');
	datahandler.add_params("neworgname" , escape(encodeURI(neworgname)), 'String');
	datahandler.add_params("regioncode" , regioncode, 'String');
	datahandler.add_params("citycode" , citycode, 'String');
	datahandler.add_params("countycode" , countycode, 'String');
	datahandler.add_params("globalpccode" , globalpccode, 'String');
	datahandler.getResultFromHashMap("errorhash" ,"messagecode" ,"document.cform.messagecode");
	datahandler.getResultFromHashMap("errorhash" ,"s1" ,"document.cform.s1");
	datahandler.add_job("j_zyladdnewcustomerfile");
	datahandler.runDataHandler();
	setTimeout("page_outTheError();","250");
}

function page_outTheError(){
	messagecode = document.cform.messagecode.value;
	s1 = document.cform.s1.value;
	if(messagecode=="P_Not_Same"){
		alert(s1+"在系统内有重复，请重新输入！");
		return;
	}
	hidDiv("submit");
}

function showDiv(element) {
    var W = document.documentElement.scrollWidth;
    var H = document.documentElement.scrollHeight;
    var selfW = document.getElementById(element).style.width;
    var selfH = document.getElementById(element).style.height;
    document.getElementById(element).style.left = (W - parseInt(selfW)) / 2 + 'px';
    document.getElementById(element).style.top = (H - parseInt(selfH)) / 2 + 'px';
    document.getElementById(element).style.display = 'block';
    var mDiv = document.getElementById("mDiv");
    mDiv.style.display = '';
    document.cform.subbutton.focus();
}

function hidDiv(element) {
    document.getElementById(element).style.display = 'none';
    document.getElementById("mDiv").style.display = 'none';
    page_initDiv();
}

var isHidden;
function frm_select(e){
	isHidden = "block";
	var _target = getPosition(e);
    var _obj = document.getElementById("summaryfrm");
    _obj.style.left = _target.x;
    _obj.style.top = _target.y + e.clientHeight ;
    _obj.style.height="250px";
    _obj.style.width="650px";
    _obj.style.zIndex = 5000;
    _obj.style.display = "block";
}

function getPosition(e) {
        var left = 0;
        var top = 0;
        while (e.offsetParent) {
            left += e.offsetLeft + (e.curentStyle? (parseInt(e.curentStyle.borderLeftWidth).NaN0()):0);
            top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
            e = e.offsetParent;
        }
        left += e.offsetLeft + (e.curentStyle ? (parseInt(e.curentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
        return {x:left, y:top};
}
function closeItemSelect(evt)
{
	var _obj = document.getElementById("summaryfrm");
	if(isHidden == "block"){
		isHidden = "none";
	}else{
		_obj.style.display = "none";
	}
	evt = evt || window.event;
        var _target = evt.target || evt.srcElement;
        if (!_target.getAttribute("Author") && _target != inputObj && _target != targetObj) {
            getObjById("Calendar").style.display = "none";
            getObjById("CalendarFrm").style.display = "none";
        }
}
function popBusinessarea_moulty(){
	if(popwindow!=null) popwindow.close();
	
    url = '<%=contextPath %>/phap/phap.datp/masterdata/cm/dataclean/ZylStdareaSelect.jsp?<%= OvalTools.randomURL() %>';
    attribute = 'height=540, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no';
	popwindow = window.open(url,'newwindow', attribute);
}

function setAreas(areaids,areanames,areacodes){

	document.cform.areaids.value = areaids;
	document.cform.businessareaname.value = areanames;
	//document.cform.businessareacode.value = areacodes;
} 
function hiddenFrm(){
	document.getElementById("summaryfrm").style.display = "none";
}

document.onclick=closeItemSelect; 

function checkDate()
{
	var startdate =document.cform.startdate.value;
	var enddate =document.cform.enddate.value;
	
if (!isEmpty(enddate))
{
  if (toDate(startdate, '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>') > toDate(enddate, '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>'))
  {
    alert('<%= message.getMessageDesc("DATE1_SHOULD_NOTLATE_THAN_DATE2") %>');
    return false;
  }
  return true;
}
return true;  
}

 </script>
 </head>
 <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
 <iframe name="summaryfrm" scrolling="yes" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;border:#909eff 1px solid;"></iframe>
 <iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
  <form name="cform" method="post" action="<%=contextPath %>/Dispatcher">
       <input type="hidden" name="pagename" value="p_customercollateedit">
       <input type="hidden" name="actionname"/>
	   <input type="hidden" name="name" value="">
  	   <input type="hidden" name="type" value="">
  	   <input type="hidden" name="clstflagvalue" value="">
  	   <custom:hidden property="proid"/>
	   <custom:hidden property="cityid"/>
       <custom:hidden property="sregioncode"/>
       <custom:hidden property="regionid"/>
       <custom:hidden property="sregionname"/>
       <custom:hidden property="scitycode"/>
       <custom:hidden property="scityname"/>
       <custom:hidden property="messagecode"/>
       <custom:hidden property="s1"/>
       <custom:hidden property="languagecode" scope="session"/>
	   <custom:hidden name="userinfo" property="userid" scope="session"/>
 <%--  page location   --%>
   <%@ include file="/inc/PageLocation.inc" %>

     <table width="100%" cellspacing="0" cellpadding="0" border="0"  onkeydown="if(event.keyCode==13) page_summary('search');">

         <tr>
             <td width="80%">
                 <table  width="100%" cellspacing="0" cellpadding="0" border="0">
                       <tr>
                         <td  align="right" width="120">
                             <font color=black><%= label.getLabelName("L_CustomerKey") + label.getLabelName("L_Colon") %></font>
                         </td>
                         <td>
                             <custom:text property="keyname"  size="15"/>
                         </td>
						 <td align="right" width="100">
                             <%= label.getLabelName("L_KeyExclude") + label.getLabelName("L_Colon") %>
                         </td>
                         <td>
                             <custom:text property="keynameexc" size="15"/>
                         </td>
                         <td style="width:60px;" class="td_right">
						<%=label.getLabelName("L_Provicetdr") +  label.getLabelName("L_Colon") %>
						 </td>
						  <td style="width:160px;" class="td_left"> <custom:hidden  property="areaids" />
					<custom:text  property="businessareaname"  label="L_BusinessAreaName" readonly="true"/>
					<a onclick="popBusinessarea_moulty()"><custom:button type="3" value="*"/></a>
						
		           </td>   <%
                                String clstflag = (String)pageContext.getAttribute("clstflag");
                                if(clstflag==null){
                                    clstflag="N";
                                }
                         %>
                       </tr>
<%-----------------------第二行---------------------%>
                       <tr>
                       <td align="right" width="120"><%= label.getLabelName("L_DealerProvince") + label.getLabelName("L_Colon") %>
                         </td>
                         <td>
                             <custom:text property="newsregioncode"  size="15" onchange="page_changeRegion('supplier')"/>
                             <a onclick="javascript:page_selectProvince('supplier');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                             <custom:text property="newsregionname"   size="20" readonly="true"/>
                         </td>
                         <td align="right" width="100">
                             <%= label.getLabelName(" L_DealerCity") + label.getLabelName("L_Colon") %>
                          </td>
                         <td>
                             <custom:text property="newscitycode"   size="15" onchange="page_changeCity('supplier')"/>
                             <a onclick="javascript:page_selectCity('supplier','city',1);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                             <custom:text property="newscityname"   size="20" readonly="true" />
                         </td>
                       </tr>
                        <tr>
              <%
                SimpleDateFormat formatter1 = new SimpleDateFormat ("yyyy-MM-dd");
                String str_date_end=formatter1.format(new Date());
                
              %>

	    <td><%= label.getLabelName("L_DatelastUpdated") + label.getLabelName("L_Colon") %></td>
	    <td>
                <custom:text property="startdate"  dataType="date"  module="IMG" size="15" />
              <a onclick="javascript:c.show(this,'cform.startdate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
              --
              <%if(pageContext.getAttribute("enddate")==null){%>
			  <custom:text property="enddate" dataType="date" dataFormatName="dateformat" module="IMG" size="15" />
			  <%}else{%>
			  <custom:text property="enddate"  dataType="date" dataFormatName="dateformat"  module="IMG"  size="15"/>
			  <%}%>
              <a onclick="javascript:c.show(this,'cform.enddate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
         </td>
                       
                       </tr>
                 </table>
                 <table>
						  <%@ include file="/inc/SummarySearch.inc" %>
                 </table>
              </td>
             <td width="20%">
             	<table>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="A" <%=clstflag.equalsIgnoreCase("A")?"checked":""%> checked="true">
							<%= label.getLabelName(" L_AllCustomerList") %>
						</td>
						<td>&nbsp;</td>             	
					</tr>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="V" <%=clstflag.equalsIgnoreCase("V")?"checked":""%>>
							<%= label.getLabelName(" L_Auto_CustomerList") %>
						</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="S" <%=clstflag.equalsIgnoreCase("S")?"checked":""%>>
							<%= label.getLabelName(" L_StandardCustoms") %>
						</td>
						<td>&nbsp;</td>
					</tr>
             	</table>
              </td>
           </tr>
                    
           <tr>
             <td colspan="2">
              <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
                 <tr class="deepblue-left">
                     <td class="title_center">
                         <input type="checkbox" name="selectall" onclick="checkAll()" style="border:0">
                     </td>
                   <%if(orgoptionvalue.equals("2")){ %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','origincustcode')"><%= label.getLabelName("L_OriginCustomerCode") %></a></td>
                   <%}else{ %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','origincustname')"><%= label.getLabelName("L_OriginCustomerName") %></a></td>
                   <%} %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','custcolcode')"><%= label.getLabelName("L_CustomerCollateCode") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','custcolcode')"><%= label.getLabelName("L_CustomerCollateName") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','dealercode')"><%= label.getLabelName("L_DealerCode") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','dealername')"><%= label.getLabelName("L_DealerName") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','sregionname')"><%= label.getLabelName("L_DealerProvince") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','scityname')"><%= label.getLabelName("L_DealerCity") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_ActivityStatus") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','lorgname')"><%= label.getLabelName("L_LorgName") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','ldatelastupdated')"><%= label.getLabelName("L_LdatelastUpdated") %></a></td>
                           <td class="title_center"><a href="javascript:page_summary('orderby','datelastupdated')"><%= label.getLabelName("L_DatelastUpdated") %></a></td>
                 <td class="title_center"><a href="javascript:page_summary('orderby','employeename')"><%= label.getLabelName("L_Operater") %></a></td>
                 </tr>
                 <%
                        String strClassType="";
                         int i = 0;
                 %>
                 <logic:iterate id="info" collection="<%= totalsummary %>" >
                 <%//show different colours in turns
                     if(i%2 == 1)
                         {
                             strClassType = "td-listrom";
                         }else{
                             strClassType = "none";
                         }
                     i++;
                 %>
                     <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'"   class="<%= strClassType %>">
                         <td class="title_center"><custom:checkbox property="orgcollateid" name="info" changedName="selorgids" style="border:0"/></td>
                         <%if(orgoptionvalue.equals("2")){ %>
                         <td>&nbsp;<custom:write  name="info" property="origincustcode"/></td>
                         <%}else{ %>
                         <td>&nbsp;<custom:write  name="info" property="origincustname"/></td>
                         <%} %>
                         <td>&nbsp;<custom:write name="info" property="custcolcode"/></td>
                         <td>&nbsp;<custom:write name="info" property="custcolname"/></td>
                         <td>&nbsp;<custom:write name="info" property="dealercode"/></td>
                         <td>&nbsp;<custom:write name="info" property="dealername"/></td>
                         <td>&nbsp;<custom:write name="info" property="sregionname"/></td>
                         <td>&nbsp;<custom:write name="info" property="scityname"/></td>
                         <td class="title_center"><custom:write name="info" property="statusname"/></td>
                          <td>&nbsp;<custom:write name="info" property="lorgname"/></td>
                         <td>&nbsp;<custom:write name="info" property="ldatelastupdated"/></td>
                         <td>&nbsp;<custom:write name="info" property="datelastupdated"/></td>
                         <td>&nbsp;<custom:write name="info" property="employeename"/></td>
                     </tr>
                  </logic:iterate>
                 <%@ include file="/inc/SummaryAction.inc" %>
               </table>
            </td>
       </tr>
       <tr>
         <td colspan="2">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td class="summary_top" ></td>
             </tr>
             <tr>
                 <td>
                 	<%
                 		if("Y".equals(optionvalue)){
                    	if(i > 0){
                 	 %>
                     <%= label.getLabelName("L_CustomerCollateCode") + label.getLabelName("L_Colon") %>
                     <custom:hidden property="orgid"/>
                     <custom:text property="orgcode" onchange="page_reload()" size="15"/>
                     <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" onclick="frm_select(this)"/>
                     <custom:text property="orgname"  readonly="true" size="25"/>
                     
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<custom:button label="L_Submit" style="width:60px;" styleClass="button1" onclick="page_go()"/>
                    <custom:button label="L_InstantModify" styleClass="button1" style="width:80px;" onclick="page_update()"/>
                    <custom:button label="L_NewCustomer" styleClass="button1" style="width:80px;" onclick="showDiv('submit')"/>
                    <%}else{ %>
                    	&nbsp;
                    <%} %>
                    <custom:button label="L_Upload" styleClass="button1" style="width:80px;" onclick="page_upload()"/>
                    <custom:button label="L_Download" styleClass="button1" style="width:80px;" onclick="page_download()"/>
                    <custom:button label="L_ALL_BIG_Execcd" styleClass="button1" style="width:80px;" onclick="big_download()"/>
					<custom:button label="L_ZhongDuanXiaZai" styleClass="button1" style="width:80px;" onclick="page_excelload()"/>
						<%}%>
                 </td>
               </tr>
           </table>
         </td>
     </tr>
     <tr>
         <td>&nbsp;</td>
     </tr>
 </table>
<div id="submit" style="background:white;width:700px;height:125px;border:5px #999999 double;position:absolute;display:none">
    <div id="close" class="deepblue-left" style="width:700px;height:20px;text-align:right;cursor:move;"><img
            src="<%=contextPath %>/images/closeXXX.jpg" style="cursor:hand" onclick="hidDiv('submit')"></div>
    <div style="text-algin:center;height:100px;">
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <table border="1" width="694px" cellspacing="0" cellpadding="0" align="center">
                        <tr>
                            <td class="need"><%= label.getLabelName("L_RefCode") + label.getLabelName("L_Colon") %></td>
                            <td><custom:text property="neworgcode" command="notnull" label="L_RefCode"/></tr>
                            <td class="need"><%= label.getLabelName("L_CostomerName") + label.getLabelName("L_Colon") %></td>
                            <td><custom:text property="neworgname" command="notnull" label="L_CostomerName"/></tr>
                        <tr>
                        <tr>
                            <td class="td-text"><%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %></td>
            				<td> 
            					<custom:text property="newregioncode" label="L_Province" size="10" readonly="true"/>
            					<a onclick="javascript:page_selectProvince('newcustomer');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            					<custom:text property="newregionname" readonly="true" size="20"/>
            				</td>
            				<td class="td-text"><%= label.getLabelName("L_City") + label.getLabelName("L_Colon") %></td>
          					<td>
            					<custom:text property="newcitycode" label="L_City" size="10" readonly="true"/>
            					<a onclick="javascript:page_selectCity1('newcustomer','city',1);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            					<custom:text property="newcityname" readonly="true" size="20"/>
           					</td>
                        <tr>
                        <tr>
            				<td class="td-text"><%= label.getLabelName("L_County") + label.getLabelName("L_Colon") %></td>
            				<td>
              					<custom:text property="newcountycode" label="L_County" size="10" readonly="true"/>
              					<a onclick="javascript:page_selectCity1('newcustomer','county',2);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
              					<custom:text property="newcountyname" readonly="true" size="20"/>
            				</td>
            				<td class="need"><%= label.getLabelName("L_SCMRole") + label.getLabelName("L_Colon") %></td>
           					<td><custom:selectdic dictType="GlobalPCCode" property="globalpccode" valueCriteria="112,113,114" defaultValue="------------" command="notnull" label="L_SCMRole"/></td>
                            
          				</tr>
                            <td class="td_center" colspan="4">
                                <input type="button" name="subbutton" style="width:60px;" value="<%=label.getLabelName("L_Confirm")%>"
                                       onclick="subDiv()"/>
                                <custom:button label="L_Cancel" style="width:60px;" onclick="hidDiv('submit')"></custom:button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</div>
</form>
<iframe name="reloadHandler" style="display:none"></iframe>
<script type="text/javascript">
window.onload = function() {
    var newMask = document.createElement("div");
    newMask.id = "mDiv";
    newMask.style.position = "absolute";
    newMask.style.zIndex = "5000";
    _scrollWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
    _scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    newMask.style.width = "100%";
    newMask.style.height = "100%";
    newMask.style.top = "0px";
    newMask.style.left = "0px";
    newMask.style.background = "#33393C";
    newMask.style.filter = "alpha(opacity=40)";
    newMask.style.opacity = "0.40";
    newMask.style.display = 'none';
    newMask.innerHTML = '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe>'
    document.body.appendChild(newMask);
    document.getElementById("submit").style.zIndex = "5002";
    var objDrag = document.getElementById("close");
    var drag = false;
    var dragX = 0;
    var dragY = 0;
    objDrag.attachEvent("onmousedown", startDrag);
    function startDrag() {
        if (event.button == 1 && event.srcElement.tagName.toUpperCase() == "DIV") {
            event.srcElement.setCapture();
            event.srcElement.style.background = "#ECECEC";
            drag = true;
            dragX = event.clientX;
            dragY = event.clientY;
        }
    };
    objDrag.attachEvent("onmousemove", Drag);
    function Drag() {
        if (drag) {
            var oldwin = event.srcElement.parentNode;
            oldwin.style.left = oldwin.offsetLeft + event.clientX - dragX;
            oldwin.style.top = oldwin.offsetTop + event.clientY - dragY;
            oldwin.style.left = event.clientX - 100;
            oldwin.style.top = event.clientY - 10;
            dragX = event.clientX;
            dragY = event.clientY;
        }
    };
    objDrag.attachEvent("onmouseup", stopDrag);
    function stopDrag() {
        event.srcElement.style.background = "#90AAC5";
        event.srcElement.releaseCapture();
        drag = false;
    };
	subDiv(1);
}
document.summaryfrm.location.href = "<%=contextPath%>/masterdata/ogm/OrgSelectCompare.jsp?<%= OvalTools.randomURL() %>";
</script>
 </body>
 </html>


